
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public class Room<T extends Comparable<T>> {
	public Set<T> people;
	
	public Room() {
		people = new TreeSet<T>();
	}
	
	public void changeRoomContents(List<T> newPeople) {
		people = new TreeSet<T>();
		people.addAll(newPeople);
	}
	
	public int size() {
		return people.size();
	}
	
	public boolean contains(T who) {
		return people.contains(who);
	}
	
	public Set<T> getDepartures(Room<T> newRoom) {
		Set<T> ourPeeps = new TreeSet<T>(people);
		Set<T> theirPeeps = new TreeSet<T>(newRoom.people);
		
		Set<T> peopleInCommon = new TreeSet<T>(ourPeeps);
		peopleInCommon.retainAll(theirPeeps);		
		
		ourPeeps.removeAll(peopleInCommon);
		ourPeeps.removeAll(theirPeeps);
		
		return ourPeeps;
	}
	
	public Set<T> getArrivals(Room<T> newRoom) {
		Set<T> ourPeeps = new TreeSet<T>(people);
		Set<T> theirPeeps = new TreeSet<T>(newRoom.people);
		
		Set<T> peopleInCommon = new TreeSet<T>(ourPeeps);
		peopleInCommon.retainAll(theirPeeps);

		theirPeeps.removeAll(peopleInCommon);
		theirPeeps.removeAll(ourPeeps);
		
		return theirPeeps;
	}
}
